Telegram Group & Telegram Channel
Форматирование чисел в f-строках

Начиная с версии Python 3.6, стали доступны f-строки. Это удобный способ форматирования текста. Но не все знают, что он умеет вставлять float числа с настраиваемым количеством знаков после запятой.

Допустим у нас есть float число pi = 3.14159265359. Если мы его просто скорвертируем в строку, то она примет следующий вид:

>>> str(3.14159265359)
'3.14159265359'


Но что если важно выписать только до сотых долей? Делается это черех f-строку:

>>> f'Число Пи это {pi:.2f}'
'Число Пи это 3.14'


После обьявления имени переменной мы вставляем следующую комбинацию: .2f, где цифра как раз и указывает, сколько знаков после запятой нужно преобразовать в строку. Более подробно это описано в PEP 498.

#fstring



tg-me.com/python_academy/771
Create:
Last Update:

Форматирование чисел в f-строках

Начиная с версии Python 3.6, стали доступны f-строки. Это удобный способ форматирования текста. Но не все знают, что он умеет вставлять float числа с настраиваемым количеством знаков после запятой.

Допустим у нас есть float число pi = 3.14159265359. Если мы его просто скорвертируем в строку, то она примет следующий вид:

>>> str(3.14159265359)
'3.14159265359'


Но что если важно выписать только до сотых долей? Делается это черех f-строку:

>>> f'Число Пи это {pi:.2f}'
'Число Пи это 3.14'


После обьявления имени переменной мы вставляем следующую комбинацию: .2f, где цифра как раз и указывает, сколько знаков после запятой нужно преобразовать в строку. Более подробно это описано в PEP 498.

#fstring

BY Python Academy




Share with your friend now:
tg-me.com/python_academy/771

View MORE
Open in Telegram


Python Academy Telegram | DID YOU KNOW?

Date: |

What Is Bitcoin?

Bitcoin is a decentralized digital currency that you can buy, sell and exchange directly, without an intermediary like a bank. Bitcoin’s creator, Satoshi Nakamoto, originally described the need for “an electronic payment system based on cryptographic proof instead of trust.” Each and every Bitcoin transaction that’s ever been made exists on a public ledger accessible to everyone, making transactions hard to reverse and difficult to fake. That’s by design: Core to their decentralized nature, Bitcoins aren’t backed by the government or any issuing institution, and there’s nothing to guarantee their value besides the proof baked in the heart of the system. “The reason why it’s worth money is simply because we, as people, decided it has value—same as gold,” says Anton Mozgovoy, co-founder & CEO of digital financial service company Holyheld.

In many cases, the content resembled that of the marketplaces found on the dark web, a group of hidden websites that are popular among hackers and accessed using specific anonymising software.“We have recently been witnessing a 100 per cent-plus rise in Telegram usage by cybercriminals,” said Tal Samra, cyber threat analyst at Cyberint.The rise in nefarious activity comes as users flocked to the encrypted chat app earlier this year after changes to the privacy policy of Facebook-owned rival WhatsApp prompted many to seek out alternatives.Python Academy from fr


Telegram Python Academy
FROM USA